<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html>
<html>
	<head>
		<base href="<%=basePath %>" />
		<head>
		<meta charset="UTF-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<title></title>
		<link rel="stylesheet" href="plugins/layui/css/layui.css" media="all" />
		<link rel="stylesheet" href="css/global.css" media="all" />
		
	</head>
	<body>
		<div id="tempybbt" class="layui-hide">
		<div class="layui-form-item" >
			<label class="layui-form-label">夜班次数</label>
			<div class="layui-input-inline">
				<input type="number" name="ybbttimes" placeholder="请输入" autocomplete="off"
					class="layui-input" >
			</div>
			<div class="layui-form-mid layui-word-aux">次</div>
		</div>
	</div>

		<div class="admin-main">

			<blockquote class="layui-elem-quote">
			
				<a href="javascript:;" class="layui-btn layui-btn" id="import">
					<input type="file" name="filename" class="layui-upload-file" id="importexcel">
				</a>
			<!-- 	<a href="user/salaryexplortexcel" class="layui-btn layui-btn">
					<i class="fa fa-shopping-cart" aria-hidden="true"></i> 导出信息
				</a> -->
				<a href="javascript:;" class="layui-btn layui-btn" id="getSelected">
					<i class="fa fa-shopping-cart" aria-hidden="true"></i> 生成本月工资条
				</a>
				<div class="layui-inline">
					<div class="layui-input-inline">
						<input type="text" id="sh-xm" placeholder="姓名.." autocomplete="off" class="layui-input" lay-verify="required">
					</div>
				</div>
				<a href="javascript:;" class="layui-btn layui-btn" id="search">
					<i class="layui-icon">&#xe615;</i> 搜索
				</a>
			</blockquote>
			<fieldset class="layui-elem-field">
				<legend>员工工资信息列表</legend>
				<div class="layui-field-box layui-form">
					<table class="layui-table admin-table">
						<thead>
							<tr>
								<th style="width: 30px;"><input type="checkbox" lay-filter="allselector" lay-skin="primary"></th>
								<th>员工编码</th>
								<th>姓名</th>
							
							
								<th>入职日期</th>
								<th>所在部门</th>
							<!-- 	<th>岗位类型</th>
								<th>用工性质</th>
								<th>负责项目</th>
								<th>工龄工资</th>
								<th>专业资格补贴</th>
								<th>通讯补贴</th>
								<th>交通补贴</th>
								<th>出车补贴</th>
								<th>夜班补贴</th>
								<th>加班补贴</th>
								<th>适岗补贴</th>
								<th>其它</th>
								<th>绩效考核工资</th>
								<th>养老保险</th>
								<th>事业保险</th>
								<th>医疗保险</th>
								<th>大病保险</th>
								<th>公积金</th> -->
							
								<th>个人所得税(工资 )</th>
								<th>个人扣款</th>
								<th>应发工资</th>
								<th>实发工资</th>
								<th>存折</th>
								<th>应发奖金</th>
								<th>个人所得税(奖金)</th>
								<th>实发奖金</th>
								<th>操作</th>
							</tr>
						</thead>
						<tbody id="content">
						</tbody>
						<tfoot >
							<tr>
								<th colspan="35 ">
									<div class="admin-table-page">
										<div id="paged" class="page">
										</div>
									</div>
								</th>
							</tr>
						</tfoot>
					</table>
				</div>
			</fieldset>
		
		</div>
		<!--模板-->
		<script type="text/html" id="tpl">
			{{# layui.each(d.list.list, function(index, item){ }}
			<tr>
				<td><input type="checkbox" lay-skin="primary"></td>
				<td>{{ vnull(item.ygbm) }}</td>
				<td>{{ vnull(item.xm) }}</td>
			
				<td>{{ vnull(item.rzrq) }}</td>
				<td>{{ vnull(item.szbm) }}</td>
				
				
				<td>{{ vnull(item.grsds) }}</td>
				<td>{{ vnull(item.grkk) }}</td>
				<td>{{ vnull(item.yfgz) }}</td>
				<td>{{ vnull(item.sfgz) }}</td>
				<td>{{ vnull(item.cz) }}</td>
				<td>{{ vnull(item.yfjj) }}</td>
				<td>{{ vnull(item.grsus1) }}</td>
				<td>{{ vnull(item.sfjj) }}</td>
				<td>
					<a href="javascript:;" data-name='{{ JSON.stringify(item) }}' data-opt="edit" class="layui-btn layui-btn-mini">编辑</a>
				</td>
			</tr>
			{{# }); }}
		</script>
		<script type="text/javascript" src="plugins/layui/layui.js"></script>
		<script>
		
			layui.config({
				base: 'js/'
			});
			//身份证号算年龄 
            function goage(n){
            	var a = new Date().getFullYear();
            	var b =parseInt(n.substr(6,4));
            	return a-b;
            }
            // 验证null/undefine
            function vnull(str){
                if(str==null || str==undefined){
					return "";
                    }else{
					return str;
                        }
                }
            
			layui.use(['paging', 'form', 'laydate', 'upload'], function() {
				var $ = layui.jquery,
					paging = layui.paging(),
					layerTips = parent.layer === undefined ? layui.layer : parent.layer, //获取父窗口的layer对象
					layer = layui.layer, //获取当前窗口的layer对象
					form = layui.form();
				var _data = {};
				//全局的AJAX访问，处理AJAX清求时SESSION超时
				$.ajaxSetup({
				    contentType:"application/x-www-form-urlencoded;charset=utf-8",
				    complete:function(XMLHttpRequest,textStatus){
				          //通过XMLHttpRequest取得响应头，sessionstatus           
				          var sessionstatus=XMLHttpRequest.getResponseHeader("sessionstatus"); 
				          loginUrl = XMLHttpRequest.getResponseHeader("location"); 
				          if(sessionstatus=='00004'){
				               //这里怎么处理在你，这里跳转的登录页面
				        	 // if( window.top != window.self ){
				  				window.top.location = loginUrl;
				  			//}
				       }
				    }
				});
				
				//公用ajax方法 
				var jsajax = function(type, url,_data){  
		              $.ajax({
						type: type,
						url:  url,
						async: false,
						data: _data,
						dataType: 'json',
						success: function(result, status, xhr) {
							if(result.flag){
							 	$(_data.ele).val( result.count);
								}
							layerTips.msg(result.msg);
							}
					});
		          }
			var data = {};
			var loadtab = function(data){ 
					paging.init({
					url: 'user/findusersalarys',  //地址
					elem: '#content', //内容容器
					params: data,
					type: 'GET',
					tempElem: '#tpl', //模块容器
					pageConfig: { //分页参数配置
						elem: '#paged', //分页容器
						pageSize: 10 //分页大小
					},
					success: function() { //渲染成功的回调
						//alert('渲染成功');
					},
					fail: function(msg) { //获取数据失败的回调
						//alert('获取数据失败')
					},
					complate: function() { //完成的回调
						//alert('处理完成');
						//重新渲染复选框
						form.render('checkbox');
						form.on('checkbox(allselector)', function(data) {
							var elem = data.elem;

							$('#content').children('tr').each(function() {
								var $that = $(this);
								//全选或反选
								$that.children('td').eq(0).children('input[type=checkbox]')[0].checked = elem.checked;
								form.render('checkbox');
							});
						});

						//绑定所有编辑按钮事件						
						$('#content').children('tr').each(function() {
							var $that = $(this);
							$that.children('td:last-child').children('a[data-opt=edit]').on('click', function() {
								//JSON.parse(jsonstr); //可以将json字符串转换成json对象 
								//JSON.stringify(jsonobj); 
								//layer.msg($(this).data('name').xm);
								var data = $(this).data('name');
								loadform(data);
								});

						});

					},
				});
			}
			layui.upload({
			    url: 'user/salaryimportexcel',
			    type: 'file'	,
			    ext: 'xls',
			    title: '信息导入（xls）'
			    ,elem: '#importexcel' //指定原始元素，默认直接查找class="layui-upload-file"
			    ,method: 'post' //上传接口的http类型
			    ,success: function(res){
				    if(res.isSuccess){
		
				    }
				}
			 });
			loadtab(data);
				//获取所有选择的列
				$('#getSelected').on('click', function() {
					var names = '';
					$('#content').children('tr').each(function() {
						var $that = $(this);
						var $cbx = $that.children('td').eq(0).children('input[type=checkbox]')[0].checked;
						if($cbx) {
							var n = $that.children('td:last-child').children('a[data-opt=edit]').data('name').gid;
							names += n + ',';
						}
					});
                  if(!names){
					layer.msg('请先选择');
                  }else{
					 $.ajax({
							type: 'post',
							url:  'salary/salarybill',
							async: false,
							data: {ids: names},
							dataType: 'json',
							success: function(result, status, xhr) {
								if(result.flag){
								 	//$(_data.ele).val( result.count);
									}
								layer.msg(result.msg);
								}
						});
                  }
					});

				$('#search').on('click', function() {
					//parent.layer.alert('你点击了搜索按钮');
					data = {xm: $('#sh-xm').val()};
					loadtab(data);
				});

				// 部门职位
				var addorganiz = function(a, o){
					$.ajax({
						type: 'get',
						url:  'organiz/findbylevl',
						data: {level:a},
						async: false,
						dataType: 'json',
						success: function(result, status, xhr) {
							if(result.flag){
								$(result.list).each(function(i,item){
							      $(o).append("<option value='" +item.organizid+"'>"+item.oname+"</option>");
								});
								}
							}
					});
				}
				var addBoxIndex = -1;
				var loadform = function(item){
					if(addBoxIndex !== -1)
						return;
					//本表单通过ajax加载 --以模板的形式，当然你也可以直接写在页面上读取
					$.get('temp/salary-form.html', null, function(form) {
						addBoxIndex = layer.open({
							type: 1,
							title: '工资修改',
							content: form,
							btn: ['保存', '取消'],
							shade: false,
							offset: ['100px', '30%'],
							area: ['600px', '400px'],
							zIndex: 19950924,
							maxmin: true,
							yes: function(index) {
								//触发表单的提交事件
								$('form.layui-form').find('button[lay-filter=edit]').click();
							},
							full: function(elem) {
								var win = window.top === window.self ? window : parent.window;
								$(win).on('resize', function() {
									var $this = $(this);
									elem.width($this.width()).height($this.height()).css({
										top: 0,
										left: 0
									});
									elem.children('div.layui-layer-content').height($this.height() - 95);
								});
							},
							success: function(layero, index) {
								//弹出窗口成功后渲染表单
	
								/**表单赋值**/
								$("#salary-up input").each(function(i,it){

					
								switch (it.name){

									case 'id': it.value = item.salaryid; break;
									case 'gid': it.value = item.gid; break;
									case 'ygbm': it.value = item.ygbm; it.readOnly =true; break;
									case 'xm': it.value = item.xm;  it.readOnly =true; break;
									case 'gjgz': it.value = item.gjgz ? item.gjgz: 0.0; break;
									case 'glgz': it.value = item.glgz ? item.glgz: 0.0; ; break;
									case 'zyzgbt': it.value = item.zyzgbt ? item.zyzgbt: 0.0; ; break;
									case 'txbt': it.value = item.txbt ? item.txbt: 0.0; ; break;	
									case 'jtbt': it.value = item.jtbt ? item.jtbt: 0.0; ; break;	
									case 'ccbt': it.value = item.ccbt ? item.ccbt: 0.0; ; break;	
									case 'ybbt': it.value = item.ybbt ? item.ybbt: 0.0;  it.readOnly =true; break;	
									case 'jbgz': it.value = item.jbgz ? item.jbgz: 0.0;  it.readOnly =true; break;	
										
									case 'qtbt': it.value = item.qtbt ? item.qtbt: 0.0; ; break;	
									case 'sgbt': it.value = item.sgbt ? item.sgbt: 0.0; ; break;	
									case 'jxkhgz': it.value = item.jxkhgz ? item.jxkhgz: 0.0; ; break;	
									case 'grkk': it.value = item.grkk ? item.grkk: 0.0;  it.readOnly =true; break;	
									case 'ylbx': it.value = item.ylbx ? item.ylbx: 0.0; ; break;	
									case 'sybx': it.value = item.sybx ? item.sybx: 0.0; ; break;	
									case 'ylbxx': it.value = item.ylbxx ? item.ylbxx: 0.0; ; break;	
									case 'dbbx': it.value = item.dbbx ? item.dbbx: 0.0; ; break;	
									case 'gjj': it.value = item.gjj ? item.gjj: 0.0; ; break;
									case 'yfjj': it.value = item.yfjj ? item.yfjj: 0.0; ; break;
									default :
										break;	
										
									} 
										
								});
								
								
								var form = layui.form();
								form.render();
								//表单校验
								form.verify({
									  numbero: function(value){
										 var reg = /(^[1-9]([0-9]+)?(\.[0-9]{1,2})?$)|(^(0){1}$)|(^[0-9]\.[0-9]([0-9])?$)/;
									    if(!reg.test(value)){
									    	layerTips.msg('请正确输入！');
									    	return "123";
									    }
									  }
									});     
								//夜班补贴
								$('input[lay-filter="ybbt"]').on('click', function() {
									layerTips.prompt(function(value, index, elem){
										  //alert(value);  //得到value
										  _data.times = value;
										  _data.ele = "input[name='ybbt']";
											jsajax('post', 'salary/gonight', _data);
										  layerTips.close(index);
										});
									});
								//加班补贴
								$('input[lay-filter="jbbt"]').on('click', function() {
									$.post('temp/jbbt-form.html', {}, function(str){
										layerTips.open({
											 title: '请假次数',
										    type: 1,
										    content: str,  //注意，如果str是object，那么需要字符拼接。
										    btn:'确定',
										    yes: function(index, layero) {
												var v1 =$(layero).find('#tempjbbt input[name="we-times"]').val();
												var v2 =$(layero).find('#tempjbbt input[name="fes-times"]').val();

												_data.ele = "input[name='jbgz']";
												_data.gjgz = $("input[name='gjgz']").val();
												_data.times1 = v1;
												_data.times2 = v2;
												jsajax('post', 'salary/overtime', _data);
												  layerTips.close(index);
											}
										  });
										});
									
									});
								//请假扣款
									$('input[lay-filter="grkk"]').on('click', function() {
									$.post('temp/grkk-form.html', {}, function(str){
										layerTips.open({
											 title: '请假明细',
										    type: 1,
										    content: str,  //注意，如果str是object，那么需要字符拼接。
										    btn:'确定',
										    yes: function(index, layero) {
												var sj =$(layero).find('#tempgrkk input[name="sjtimes"]').val();
												var bj =$(layero).find('#tempgrkk input[name="bjtimes"]').val();
												var cj =$(layero).find('#tempgrkk input[name="cjtimes"]').val();
												var hj =$(layero).find('#tempgrkk input[name="hjtimes"]').val();
												_data.ele = "input[name='grkk']";
												_data.gjgz = $("input[name='gjgz']").val();
												_data.sjtimes = sj;
												_data.bjtimes = bj;
												_data.hjtimes = hj;
												_data.cjtimes = cj;
												_data.id = $("input[name='gid']").val();
												jsajax('post', 'salary/leave', _data);
												  layerTips.close(index);
											}
										  });
										});
									
									});
								//计算个人所得税和实际工资
								form.on('submit(edit)', function(data) {
									$.ajax({
										type: 'post',
										url:  'salary/update',
										data: data.field,
										dataType: 'json',
										success: function(result, status, xhr) {
												if(result.flag){
												layer.closeAll();
												location.reload(); //刷新
												}else{
													layerTips.msg(result.msg);
													}
											}
									});
									
									return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。									
								});
								//console.log(layero, index);
							},
							end: function() {
								addBoxIndex = -1;
							}
						});
					});
				}

				$('#import').on('click', function() {
					var that = this;
				
				});
			});
		</script>
	</body>
	</body>

</html>